home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/awk -f
- # -*- awk -*-
- #
- # $Header: /usr/bfr/src/test/RCS/fts-f-trim-decls,v 1.1 1995/01/18 17:39:14 abel Exp $
- #
- #********************************************
- #
- # convert character strings FORTRAN decls to STRINGs
- #
- # input must not contain comments, splitted lines and multiple decls
- # NOTE: doesn't handle thigs more complicated than char strings
- #
- #
- #********************************************
- #
- # Written by Alexander L. Belikoff, 1994
- # Copyright (C)1994 Alexander L. Belikoff
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- #********************************************
- #
- # $Log: fts-f-trim-decls,v $
- # Revision 1.1 1995/01/18 17:39:14 abel
- # Initial revision
- #
- #
- #********************************************
-
-
- # CHARACTER*33 A -> %STRING% A(33)
- # CHARACTER*(*) A -> %STRING% A(*)
-
- $0 ~ /^ +CHARACTER[ \t]*\*[ \t]*[0-9]+[ \t]/ ||
- $0 ~ /^ +CHARACTER[ \t]*\*[ \t]*\([ \t]*\*[ \t]*\)[ \t]/ {
-
- res = $0
- gsub(/[ \t]*\*[ \t]*/, "*", res)
- gsub(/[ \t]*\([ \t]*/, "(", res)
- gsub(/[ \t]*\)[ \t]*/, ") ", res)
- res = substr(res, index(res, "*") + 1)
- len = res
-
- if (len ~ /^\(\*\) .*$/) {
- res = substr(res, index(res, ")") + 1)
- len = "*"
- }
- else {
- res = substr(res, index(res, " "))
- sub(/[ \t]+.*$/, "", len)
- }
-
- len = "(" len ")"
-
-
- res = " %STRING%" res
- gsub("\,", len ", ", res)
- res = res len
-
- print res
- next
- }
-
-
- # CHARACTER A*(*) -> %STRING% A(*)
-
- $0 ~ /^ +CHARACTER/ && $0 ~ /\*[ \t]*\([ \t]*\*[ \t]*\)/ {
-
- res = $0
- gsub(/[ \t]*\*[ \t]*/, "*", res)
- gsub(/[ \t]*\([ \t]*/, "(", res)
- gsub(/[ \t]*\)[ \t]*/, ") ", res)
- sub("CHARACTER", "%STRING%", res)
- gsub(/\*\(\*\)/, "(*)", res)
-
- print res
- next
- }
-
-
- # CHARACTER A*NNN -> %STRING% A(NNN)
-
- $0 ~ /^ +CHARACTER[ \t]*[^\*]/ &&
- $0 ~ /\*[ \t]*[0-9]/ {
-
- res = $0
- gsub(/\*/, " * ", res)
- gsub(/,/, " , ", res)
-
- res = substr(res, index(res, "C"))
- i1 = index(res, " ")
-
- npc = split(substr(res, i1), pieces, " ")
-
- i = 1
-
- while (i <= npc) {
- typ = " CHARACTER "
- res = pieces[i]
- i++
-
- if (index(pieces[i], "*")) {
- res = res "(" pieces[i+1] ")"
- typ = " %STRING% "
- i += 2
- }
-
- if (index(pieces[i], ",")) {
- res = res pieces[i]
- i++
- }
-
- print typ res
- }
-
- next
- }
-
-
- { print }
-
- # end of $Source: /usr/bfr/src/test/RCS/fts-f-trim-decls,v $
-